<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/>
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="/h5/css/all.css">
    <link rel="stylesheet" type="text/css" href="/h5/css/app.css">
    <link rel="stylesheet" type="text/css" href="/h5/css/money.css">
    <script type="text/javascript" src="/h5/js/jquery.min.js"></script>
    <script type="text/javascript" src="/h5/js/all.js"></script>
</head>
<body style="font-size: 12px">


<div class="divbodyH5 moneyDiv">
    <div id="settingTitle">
        <b>信用等级</b>
        <a class="back" onclick="MC.back()"> <img src="/h5/images/return.png" id="settingRtn"></a>
    </div>

    <div class="myTable">
        <div class="levelDiv">
            <span class="span">当前信用等级：</span>
            <select style="display: none" id="levelselect">
            </select>
        </div>
        <div class="levelDiv valueDiv level__btn">
            <span class="span zhuanru">需要转入</span>
            <span class="span" id="money">0</span>
            <span class="span">元</span>
            <a class="btn queding">确定修改</a>
        </div>


    </div>

    <div class="shuoming">
        <p class="titlep">
            <i>*</i>存入保证金越多,等级越高,工厂越能得到信任<br>
            <i>*</i>注意：如果有尚未交易完成的单子,信用等级无法降低
        </p>
        <ul class="ul levelnamelist">
            <li class="title clearfix">
                <span class="z">等级名称</span>
                <span class="y">需要存入金额</span>
            </li>
        </ul>
    </div>

    <script>

        $(function () {
            var moneyval=0;
            MC.api('getLevelInfo', {}, function (LevelInfo) {
                for (var i in LevelInfo) {
                    var one = LevelInfo[i];
                    var li = '<option value ="'+i+'">'+one.name+'</option>';
                    $('#levelselect').append(li);
                    var li='<li class="clearfix">\n' +
                        '                <span class="z">'+one.name+'</span>\n' +
                        '                <span class="y">'+one.money+'元</span>\n' +
                        '            </li>';
                    $('.levelnamelist').append(li);
                }
                MC.api('getuserLevel', {}, function (user) {
                    var select=$('#levelselect');
                    var money=user.info.money;///当前用户等级的价额
                    select.val(user.type);
                    select.show();
                    select.on('change',function(){
                        var type=select.val();
                        var nowselect=LevelInfo[type];
                        var selectMoney=nowselect.money;///当前选择的价额
                        ///console.log(money,selectMoney);
                        moneyval=money-selectMoney;
                        if(money==selectMoney){
                            $('.valueDiv').hide();
                        }else if(money<selectMoney){
                            $('.valueDiv').show();
                            $('.valueDiv .zhuanru').text('需要转入:');
                            $('.valueDiv #money').text(selectMoney-money);
                        }else{
                            $('.valueDiv').show();
                            $('.valueDiv .zhuanru').text('可以转出:');
                            $('.valueDiv #money').text(money-selectMoney);
                        }
                    });


                });
            });

            $('.valueDiv .queding').click(function(){
                MC.api('setuserLevel', {
                    level:$('#levelselect').val(),
                    moneyval:moneyval
                }, function (user) {
                    MC.msg.alert("修改成功",function(){
                        location.reload();
                    });
                    //
                });
            });

        });
    </script>

</div>


</body>
</html>